package com.oracle.outsidein;

import com.oracle.outsidein.pool.ConvertResult;
import com.oracle.outsidein.pool.ConvertTaskInfo;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;

@Slf4j
@Getter
@Setter
public class OutsideinConverter {
    private OutsideinManager outsideinManager;
    private ConvertTaskInfo info = new ConvertTaskInfo();

    private OutsideinConverter() {
    }

    public static OutsideinConverter make(OutsideinManager outsideinManager) {
        OutsideinConverter outsideinConverter = new OutsideinConverter();
        outsideinConverter.setOutsideinManager(outsideinManager);
        return outsideinConverter;
    }

    public OutsideinConverter convert(String src) {
        info.setSrcFile(src);
        return this;
    }

    public OutsideinConverter to(String dst) {
        info.setDstFile(dst);
        return this;
    }

    public OutsideinConverter wv2zip(boolean wv2zip) {
        info.setWv2zip(wv2zip);
        return this;
    }

    public OutsideinConverter wv2mht(boolean wv2mht) {
        info.setWv2mht(wv2mht);
        return this;
    }

    public ConvertResult execute() throws ExecutionException, InterruptedException {
        OutsideinManagerConfig config = outsideinManager.getConfig();
        info.setTaskTimeout(config.getTaskTimeout());
        ConvertResult convertResult = outsideinManager.execute(info);
        log.debug(convertResult.toString());
        return convertResult;
    }
}
